package javaDemo.jvm.day_02_01_HeapAdjust;

import java.util.Random;

/**
 * @Description 堆参数调优
 * @Author
 * @Date 2020/11/21 10:05
 * @Version 1.0
 */
public class TestHeapAdjust {

    public static void main(String[] args) {
//        test01();
        test02();
    }

    private static void test02() {
        //【试验二】：模拟出现 OutOfMemoryError，查看具体的 GC 过程！-Xms10m -Xmx10m -XX:+PrintGCDetails
        String str = "";
        while (true){
            str += str + new Random().nextInt(888888888) + new Random().nextInt(99999999);
        }
    }

    private static void test01() {
        //【试验一】：调整JVM参数，核实实际内容 -Xms1024m -Xmx1024m -XX:+PrintGCDetails
        long maxMemory = Runtime.getRuntime().maxMemory();      //-Xmx
        long totalMemory = Runtime.getRuntime().totalMemory();  //-Xms
        System.out.println("-Xmx:" + maxMemory + " (字节);" + maxMemory/(1024*1024) + "MB");
        System.out.println("-Xms:" + totalMemory + " (字节);" + totalMemory/(1024*1024) + "MB");
    }
}
